<%@page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="/common/taglibs.jsp"%>
<%
	String id = request.getParameter("customerID");
	String name = request.getParameter("name");
	String telephone = request.getParameter("telephone");
	String qq = request.getParameter("qq");
	String query_other = request.getParameter("query_other");
	String state = request.getParameter("state");
	String company=request.getParameter("company");
	String action = "cust";
	String url = action+"?t="+Utils.getSystemMillis();
	String flag=request.getParameter("flag");
	if(!Utils.isNull(name)){
	 	url += "&customer.name="+name;
	}else name = "";
	if(!Utils.isNull(telephone)) url += "&customer.telephone="+telephone;
	else telephone = "";
	if(!Utils.isNull(company)) url += "&customer.company="+company;
	else company = "";
	if(!Utils.isNull(qq)) url += "&customer.qq="+qq;
	else qq = "";
	if(!Utils.isNull(id)) url += "&customer.customerID="+id;
	else id = "";
	if(!Utils.isNull(state)) url += "&customer.state="+state;
	else state = "";
	if(!Utils.isNull(query_other)) url += "&query_other="+query_other;
	else query_other = "";
	String editJsp = jspName.replace("list","info");
	String usertype = (String)session.getAttribute(Config.USER_TYPE);
	int utype = 1;
	if(usertype!=null)
		utype = Integer.valueOf(usertype);
	String disp = "";
	if(utype==Config.USER_TYPE_COMMON) 
		disp = "style='display:none' ";
	String query = request.getParameter("query");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>   
 
	<link href="../ui/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="../ui/lib/ligerUI/skins/Gray/css/dialog.css" rel="stylesheet" type="text/css" />
	<script src="../ui/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>   
    <script src="../ui/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="../ui/lib/ligerUI/js/ligerui.all.min.js" type="text/javascript"></script> 
    <link href="../ui/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    
	<script src="../ui/helper.js" type="text/javascript"></script> 
	<script type="text/javascript">
    var grid=null; 
    var datas;
    var datas2;
    $(function () {   
	  		$("form").ligerForm();
            $.getJSON(encodeURI(encodeURI('<%=url%>')) ,
            function(json) 
            {
                var colnames="";
                for(var i in json.Rows[0])  
                {
   	             		var hides='';
                        if(i=='HideID') 
                        	hides = ',hide:true';
                        colnames+=",{name:'"+i+"',display:'"+i+"',width: 100" + hides +"}";
                }
                colnames=colnames.substr(1,colnames.length);
                datas=json;
                eval(                
                        "grid=$('#grids').ligerGrid({"+
                        "checkbox: true,"+
                        "columns:["+colnames+"],"+   
                        "data:datas,"+    
                        "dataAction:'local',"+
                        "height: '90%',"+
                        "pageSize:<%=Config.PAGE_SIZE%>,"+
                         <% if(Utils.isNull(query)&&utype!=Config.USER_TYPE_FINANCE){%>
                        "toolbar: { items: ["+						
                        "{ text: '添加',click:f_addUser, icon: 'plus'},{ line:true }"+
                        ",{ text: '查看',click:f_viewUser, icon: 'view'},{ line:true }"+
                        ",{ text: '修改',click:f_editUser, icon: 'edit'},{ line:true }"+
                        ",{ text: '禁用',click:f_forbidUser, icon: 'lock'},{ line:true }"+
                        <% if(Utils.isNull(query)&&utype!=Config.USER_TYPE_COMMON){%>
                        ",{ text: '删除',click:f_delUser, icon: 'delete'},{ line:true }"+	
                        <%}%>
                        ",{ text: '转移',click:t_tranOfUser, icon: 'prev'},{ line:true }"+ 
					    ",{ text: '导出Excel',click:downloadThis,icon: 'save'}"+
                        "]},"+
                         <%}%>
                        "totalRender: f_totalRender,"+
                        "heightDiff:-12,"+
                        "isChecked: f_isChecked, onCheckRow: f_onCheckRow,onSelectRow : f_onSelectRow, onCheckAllRow: f_onCheckAllRow"+
                        "});"
                    );                                    
            }); 
            
            myGrid2= $("#grids2").ligerGrid({
        		 checkbox: false,
                 columns:[	{ display: '编号', name: 'transferId', width: 150, type: 'int' },
                             { display: '客户编码', name: 'customerId' },
                             { display: '状态', name: 'transferState',render: function (rowdata, rowindex){
                            	if(rowdata.transferState=='0'){
                            		return '新建';
                            	}else if(rowdata.transferState=='1'){
                            		return '审核中';
                            	}else if(rowdata.transferState=='2'){
                            		return '审核通过';
                            	}else if(rowdata.transferState=='3'){
                            		return '审核不通过';
                            	}else if(rowdata.transferState=='4'){
                            		return '完成';
                            	}
                             }},
                             { display: '状态', name: 'state',render: function (rowdata, rowindex){
                            	if(rowdata.state=='0'){
                            		return '启用';
                            	}else if(rowdata.state=='1'){
                            		return '作废';
                            	}
                             }},
                             { display: '转账账号', name: 'transferAccount', width: 150 },
                             { display: '转账金额', name: 'transferAmount', width: 120,type:'float' },
                             { display: '说明', name: 'remark', width: 150 },
                             { display: '创建人', name: 'userName' },
                             { display: '创建时间', name: 'createTime' },
                             //{ display: '添加时间', name: 'createDate' ,width: 150,type:'date',render: function (item){
                            	//return new Date( item.createDate).pattern("yyyy-MM-dd HH:mm:ss");
                             //} },
                             { display: '最后操作人', name: 'luserName' },
                             { display: '最后操作时间', name: 'updateTime' }
                             ], 
                             isScroll: true, showToggleColBtn: false, width: '100%',
                             height:'40%',
                 			 showTitle: false, columnWidth: 100  , frozen:false, totalRender: f_totalRender2
         
             });
    });  
	function f_totalRender(){
		return datas.totalRender;
	}
	
	function f_totalRender2()
        {
        	if(datas2!=null){
        		return datas2.totalRender; 
        	}
            return "";
        }
	
	function submitThis(){
		form1.action = "<%=jspName%>"; 
		form1.submit();
	}
	
	function f_onSelectRow(data, rowindex, rowobj){
		queryTransferList(data.HideID);
	}
	
	function queryTransferList(customerId){
		var url2 = "transfer?transfer.customerId="+customerId+"&transfer.transferState=99";

       $.getJSON(url2,function(json){
    	    datas2 = json;
	       	myGrid2.set({ data: datas2 }); 
       });
	}
	
 	function downloadThis(){
		form1.action = "../common/download.jsp?name=<%=jspName%>"; 
		form1.fb.value = getDatasValue(datas);	
		form1.submit();
	}
	function f_forbidUser()
        {
        	if(checkedCustomer.length==0){
				 $.ligerDialog.warn('<br/>请选择一个客户');
				 return ;	
			} 
			if(checkedCustomer.length>1){
				 $.ligerDialog.warn('<br/>你选择了多个客户,请选择单个客户');
				 return ;	
			}
			$.ligerDialog.confirm('<br/>确定要禁用'+checkedCustomer+'客户吗？',
                 	function (yes) {
	                 	if(yes==true) {
	                 		form1.action = "<%=action%>?action=forbid&customerID="+checkedCustomer;
							form1.submit();   
	                 	}
                 	} 
            );
            //alert(checkedCustomer.join(','));
    }
	 function f_onCheckAllRow(checked)
        {	 
            for (var rowid in this.records)
            {
                if(checked)
                    addCheckedCustomer(this.records[rowid]['HideID']);
                else
                    removeCheckedCustomer(this.records[rowid]['HideID']);
            }
        }
 
        var checkedCustomer = [];
        function findCheckedCustomer(HideID)
        {
            for(var i =0;i<checkedCustomer.length;i++)
            {
                if(checkedCustomer[i] == HideID) return i;
            }
            return -1;
        }
        function addCheckedCustomer(HideID)
        {
            if(findCheckedCustomer(HideID) == -1)
                checkedCustomer.push(HideID);
        }
        function removeCheckedCustomer(HideID)
        {
            var i = findCheckedCustomer(HideID);
            if(i==-1) return;
            checkedCustomer.splice(i,1);
        }
        function f_isChecked(rowdata)
        {
            if (findCheckedCustomer(rowdata.HideID) == -1)
                return false;
            return true;
        }
        function f_onCheckRow(checked, data)
        {
            if (checked) addCheckedCustomer(data.HideID);
            else removeCheckedCustomer(data.HideID);
        }
        function f_getChecked()
        {
            alert(checkedCustomer.join(','));
        }
        function f_addUser(){
			location.href = "cust?action=add" ;      
        }
		function f_editUser(){
			if(checkedCustomer.length==0){
				 $.ligerDialog.warn('<br/>请选择一个客户');
				 return ;	
			}else if(checkedCustomer.length>1){
				$.ligerDialog.warn('<br/>您选择了'+checkedCustomer.length+'个客户<br/><br/>请选择单个客户');
				return;
			}
			form1.action = "<%=action%>?action=display&customerID="+checkedCustomer;
			form1.submit();   
        }
		function f_viewUser(){
			if(checkedCustomer.length==0){
				 $.ligerDialog.warn('<br/>请选择一个客户');
				 return ;	
			}else if(checkedCustomer.length>1){
				$.ligerDialog.warn('<br/>您选择了'+checkedCustomer.length+'个客户<br/><br/>请选择单个客户');
				return;
			}
			form1.action = "<%=action%>?action=view&customerID="+checkedCustomer;
			form1.submit();   
        }

		function f_inputUser(){
			 location.href =  '<%=jspName%>?customerID='+ $("#id").val()+'&name='+ $("#name").val()+'&company='+$("#company").val()+'&telephone='+ $("#telephone").val()+'&query=<%=query%>'+"&qq="+ $("#qq").val()+"&query_other="+ $("#other").val();
	    }
        
        function f_findUser(customerID){
			location.href = '<%=jspName%>?customerID='+customerID+'&query=<%=query%>';
        }
        function f_delUser()
        {
        	if(checkedCustomer.length==0){
				 $.ligerDialog.warn('<br/>请选择一个客户');
				 return ;	
			} 
			if(checkedCustomer.length>1){
				 $.ligerDialog.warn('<br/>你选择了多个客户,请选择单个客户');
				 return ;	
			}
			$.ligerDialog.confirm('<br/>确定要删除'+checkedCustomer+'客户吗？',
                 	function (yes) {
	                 	if(yes==true) {
	                 		form1.action = "<%=action%>?action=delete&customerID="+checkedCustomer;
							form1.submit();   
	                 	}
                 	} 
            );
            //alert(checkedCustomer.join(','));
        }
        function t_tranOfUser(){
        	if(checkedCustomer.length==0){
				 $.ligerDialog.warn('<br/>请选择一个客户');
				 return ;	
			} 
			/* if(checkedCustomer.length>1){
				 $.ligerDialog.warn('<br/>你选择了多个客户,请选择单个客户');
				 return ;	
			} */
           // alert(checkedCustomer);
			//$("#custid").html(checkedCustomer.join("','"));	
    		$.ligerDialog.open({ target: $("#target_t"),title:'转移',height: 80,width: 450,isResize: true,showMax:true, 
    			buttons: [
    			{ text: '确定', 
    				onclick: function (item, dialog) {
    					location.href = '<%=action%>?action=tranToUser&customer.customerID='+checkedCustomer
    					+'&change_user='+$("#change_user").val();
    				} },
    			{ text: '取消', onclick: function (item, dialog) { dialog.hide(); } } ] }); 
    		
        }
        
    	function getSelceted(){
			if(checkedCustomer.length==0){
				 $.ligerDialog.warn('<br/>请选择一个客户');
				 return 'error';	
			}else if(checkedCustomer.length>1){
				$.ligerDialog.warn('<br/>您选择了'+checkedCustomer.length+'个客户<br/><br/>请选择单个客户');
				return 'error';
			}
			/*
			var rows = grid.getCheckedRows();
			var str = "";
           	 $(rows).each(function ()
            {
            	var s = this;
            	var i = 1;
                for(var n in s){  
		           	if(i==1||i==3||i==6||i==8||i==11)
		           		str += s[n]+",";  
		           	i++;
	      		} 
            });
            */
			return (checkedCustomer); 
        }
</script>
	 
</head>
<body style="padding:0 2px 2px 2px;" >
<form name="form1" method="post" id="form1">
<textarea name="fb"  style="display:none" ></textarea> 
<table height="60" cellpadding="0" cellspacing="0" class="l-table-edit" >
<!-- //客户姓名  手机    QQ -->
	 <tr>
      <td width="59" align="right" class="l-table-edit-td">客户ID：</td>
      <td  width="128"align="left" class="l-table-edit-td"><input type="text" id="id" name="id" value="<%=id%>" /></td>
      <td width="59" align="right" class="l-table-edit-td">公司名：</td>
      <td  width="128"align="left" class="l-table-edit-td"><input type="text" id="company" name="company" value="<%=company %>" /></td>
      <td width="60" align="right" class="l-table-edit-td">客户姓名：</td>
      <td width="128" align="left" class="l-table-edit-td"><input name="name" type="text" id="name" value="<%=name %>" /></td>
      <td  align="right" width="100" colspan="2"  class="l-table-edit-td" <%=disp%>> 所属业务员工号：</td>
      <td align="left"  width="128"class="l-table-edit-td" <%=disp%>><input type="text" id="other" name="query_other" value="<%=query_other %>" /></td>  
      <td colspan="2" align="center" class="l-table-edit-td"> <input type="button" value="查询" id="Button1" class="l-button l-button-submit" onclick="f_inputUser()" /></td>
      <td width="50" align="left" class="l-table-edit-td" style="display: none">手机号：</td>
      <td width="50" align="left" class="l-table-edit-td" style="display: none"><input type="text" id="telephone" name="telephone" value="<%=telephone %>" /></td>
    </tr> 
    <tr>
      <td align="right" class="l-table-edit-td" style="display: none">QQ：</td>
      <td align="left" class="l-table-edit-td" style="display: none"><input type="text" id="qq" name="qq" value="<%=qq %>" /></td>
      
    </tr>

    <%-- <tr>
      <td align="right" class="l-table-edit-td">客户状态</td>
      <td align="left" class="l-table-edit-td">
          <select id='state' name='state'>
              <option  value ="*">全部</option>
			  <option value ="0">已启用</option>
			  <option value ="1">已停用</option>
			  <option value="2">已转移</option>
		</select>
	</td>
      <td colspan="2" align="right" class="l-table-edit-td"><p>&nbsp;</p></td>
      <td colspan="2" align="left" class="l-table-edit-td">&nbsp;</td>
    </tr> --%>
  </table> 
 
<div >
<div id='grids' ></div></div>
<div id='grids2' ></div></div>
 <div id="target_t" style="display:none" >
  <table cellpadding="0" cellspacing="0" class="l-table-edit" >
    <tr>
      <td align="right" class="l-table-edit-td">转移到 ：</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="change_user" name="change_user"/> </td><td>工号上。</td>
    </tr>
</table> 
 </div>
  </form> 
 
</body>
</html>
